const express = require("express");
const pool = require("../pool.js");
//使用路由器
var router = express.Router();
router.post("/log",(req,res)=>{
	var obj = req.body;
	//非空验证
	var _phone = obj.phone;
	var _pwd = obj.pwd;
	if (!_phone) {
		res.send({
			code:402,
			msg:"账号不能为空"
		});
		return;
	}
	if (!_pwd) {
		res.send({
			code:402,
			msg:"密码不能为空"
		});
		return;
	}
	var sql = "SELECT * FROM user WHERE phone=? AND pwd=?";
	pool.query(sql,[_phone,_pwd],(err,result)=>{
		if(err) throw err;
		if(result.length>0){
			result = JSON.stringify(result[0]);
			result = JSON.parse(result);
			res.send({
				"code":200,
				"msg":"验证成功",
				"uid":result.uid
			});
		}else{
			res.send({
				code:301,
				msg:"用户名或密码错误"
			})
		}
	})
})


module.exports = router;
